package leetcode.剑指offer.剑指II;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/9/25 14:52
 * @description：
 */
public class 剑指_II_003_前n个数字二进制中1的个数 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }

    class Solution {
        public int[] countBits(int n) {
            int[] res = new int[n + 1];
            for (int i = 0; i <= n; i++) {
                if (i % 2 == 0) res[i] = res[i / 2];
                else res[i] = res[i - 1] + 1;
            }
            return res;
        }
    }
}
